/*
 * usart.c
 *
 * Created: 01/12/2012 12:20:33 a.m.
 *  Author: Rober
 */ 

#include "MyDefines.h"
#include "avr/io.h"

//RAM VARIABLES
unsigned char rub_MsgReceived;

//Function Prototypes
void usart_init(void);
void usart_send(unsigned char lub_char);
unsigned char usart_read(void);


/**************************************************************
 *  Name                 :  usart_init
 *  Description          :	
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
void usart_init(void)
{
	UBRRH=0x00;
	UBRRL = 0x33; // Tx Speed => 9600 bps
	UCSRB = (1 << RXCIE) | (1 << RXEN) | (1 << TXEN) | (1 << UCSZ2); // Rx Interruption => Enable, Rx => Enable, Tx => Enable   
	UCSRC =	(1<<URSEL)|(0<<USBS)|(1<< UCSZ0) | (1<< UCSZ1); //| // USART WORD => 8 bits
}

/**************************************************************
 *  Name                 :  usart_init
 *  Description          :	
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
void usart_send(unsigned char lub_char)
{
	UCSRB|= (1 << TXB8);
	TxMsg = lub_char;
	while (!(UCSRA & (1<<TXC)))
	{
		;
	}
}

/**************************************************************
 *  Name                 :  usart_init
 *  Description          :	
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
unsigned char usart_read(void)
{
	unsigned char lub_DataReceived;
	lub_DataReceived = UCSRB & (1 << RXB8);
	return RxMsg;
}
